 import java.sql.*;
 public class  basedato{
 public static void main(String[] args) {
    //ejecutelo con java -cp .:/usr/share/java/postgresql.jar basedato
    String driver = "org.postgresql.Driver";
    String connectString = "jdbc:postgresql://localhost:5432/press2";
    String user = "press2";
    String password = "durazn0*21";

    try{
    Class.forName(driver);
    Connection con = DriverManager.getConnection(connectString, user , password);
    Statement stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery("SELECT * FROM cargo");

    while (rs.next()){
    System.out.println("Cargo " + rs.getString("cargo"));
    }

    stmt.close();
    con.close();

    }

    catch ( Exception e ){
    System.out.println(e.getMessage());
    }
 }
}
